%%%%%%%%%% class clarification %%%%%%%%%%
% 模板声明

\NeedsTeXFormat{LaTeX2e}[2007/10/19]
\ProvidesClass{watercrystal}
              [2012/07/06 v0.8
The LaTeX template for papers of water-crystal test]
\typeout{Document Class `buaathesis' v0.8 by BHOSC (2012/07)}

%%%%%%%%%% class options %%%%%%%%%%
% 模板选项

% 其余选项传递给ctexbook
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{ctexart}}
\ProcessOptions\relax
% 加载（继承）ctexart宏包
\LoadClass[a4paper,twoside]{ctexart}[2007/10/19]
% cs4size,fancyhdr,hyperref---this options is deprecated in ctex

%%%%%%%%%%%% title %%%%%%%%%%%
\newcommand{\titleContent}{}
\let\oldAmtbTitle\title
\renewcommand{\title}[1]{%
    \renewcommand{\titleContent}{#1}
    \oldAmtbTitle{\textbf{#1}}
}

%%%%%%%%%%%%%% font %%%%%%%%%%%%
\setCJKfamilyfont{fangzhenglishu}{方正隶书简体.ttf}
\newcommand{\lishu}{\CJKfamily{fangzhenglishu}}

%%%%%%%%%% global package %%%%%%%%%%
% 全局通用宏包
\RequirePackage{fancyhdr}
\RequirePackage{ifthen}


\ctexset{
    section = {
        numbering = false,% 标题不显示编号
        titleformat = \LARGE,
        format = \lishu
    },
    subsection = {
        numbering = false,% 标题不显示编号
        titleformat = \Large,% 小四号字
        format = \kaishu % 楷体
    }
}
%%%%%%%%%% page margin %%%%%%%%%%
% 页面边距

\RequirePackage{geometry}
\newgeometry{
    top=16mm, bottom=20mm, left=12mm, right=12mm,
    headsep=5mm,
}
\savegeometry{water_crystal_geometry}
\loadgeometry{water_crystal_geometry}

\setlength{\columnsep}{30pt}%column之间的间隔
\setlength{\columnseprule}{0.3pt}%分栏竖线的宽度，0不显示


%%%%%%%%%% header & footer %%%%%%%%%%
% 页眉页脚

\RequirePackage{fancyhdr}
\fancypagestyle{plain}{ % first page style
    \fancyhf{}
    \fancyfoot[L]{
        \textbf{\pageCN}
        {\copyright\small  本文由艾斯维尔集团2006年在美国出版。版权所有\\
        \qquad\qquad ISSN 1550-8307/06/\$32.00
        }
    }
    \fancyfoot[R]{
        \textbf{\journal}\\
        {\small doi:10.1016/j.explore.2006.06.004}
    }
    \renewcommand{\headrulewidth}{0.5bp}
}
% 从第二页开始的style
\fancyhf{}
\fancyfoot[LE,RO]{\textbf{\runtitle}}
\fancyfoot[LO,RE]{
    \ifthenelse{\isodd{\thepage}} %\value{page}=1
        {\textbf{\pageCN \quad \journal}}%奇数页
        {\textbf{\journal \quad \pageCN}}%偶数页
}
\renewcommand{\headrulewidth}{0.5bp} % 页眉线宽度
\renewcommand{\footrulewidth}{0.5bp} % 页脚线宽度

\pagestyle{fancy}

\newcommand{\journal}{《探索》杂志\ 二零零六年\ 九/十月刊\ 第二卷\ 第五期}
\newcommand{\runtitle}{远程意念作用对水结晶的影响}

\newcommand{\pageCN}{第\zhnumber{\thepage}页}
% \newcommand{\pageCN}{第{\thepage}页}

%%%%%%%%%% settings for custom pages %%%%%%%%%%
% 首页重定义

% 双栏版式中的单栏（跨栏）解决方案，在texlive上报错：
% TeX capacity exceeded, sorry [save size=80000]
\RequirePackage[original,runin]{abstract} %这个包提供了单栏的abstract，但是必须配合
\RequirePackage{environ}
\RequirePackage{multicol}
\renewcommand{\abstractname}{\vspace{-\baselineskip}} %不显示“摘要”两个字
% \setlength{\absparindent}{0pt}%段落无缩进
% \setlength{\absleftindent}{0pt}%左右无margin
% \setlength{\absrightindent}{0pt}
\NewEnviron{cabstract}{
    \twocolumn[ % 主要是这里是方括号没法分放在普通的newenvironment环境里所以只好再加载另一个包environ可以提取环境中的内容\BODY
        \date{} % donot show date
        \maketitle
        \vskip -4em
        \rule{\textwidth}{0.4pt} %横线
        \begin{onecolabstract} % provided by abstract package.
            \begin{multicols}{2}% 在摘要里也显示双栏
                \BODY
            \end{multicols}
        \end{onecolabstract}
        % \vspace*{\fill}
        \vspace{-2ex}
        \rule{\textwidth}{0.4pt} %横线
        \vspace*{\fill} % 让横线垂直距离适当
    ]
    \saythanks %显示thanks的内容为脚注，必须在双栏之后加这句话，否则不显示
}

%%%%%%%%%%%%%%%%%% author %%%%%%%%%%%%%%%%
% http://tex.stackexchange.com/q/9594
\RequirePackage{authblk}
\renewcommand\Authands{, }
\renewcommand\Affilfont{\kaishu\small}

%%%%%%%%%%% footnotes without markers %%%%%%%%%%%%
% http://tex.stackexchange.com/q/30720
% http://stackoverflow.com/a/1812224
% http://tex.stackexchange.com/a/14401
\newcommand\blfootnote[1]{%
  \begingroup
  \renewcommand\thefootnote{}\footnote{#1}%
  \addtocounter{footnote}{-1}%
  \endgroup
}

%%%%%%%%%% list %%%%%%%%%%
% 列表 copy from buaathesis

\RequirePackage{enumitem}
\setlist{noitemsep}
\setlist[1,2]{labelindent=\parindent}
\setlist[enumerate,1]{label=\arabic*、}
\setlist[enumerate,2]{label=（\arabic*）}
\setlist{
    topsep=0pt,
    itemsep=0pt,
    partopsep=0pt,
    parsep=\parskip,
}

%%%%%%%%%% cross reference %%%%%%%%%%
% 交叉引用

\RequirePackage[xetex,unicode]{hyperref}
\hypersetup{colorlinks}
\hypersetup{hidelinks}
\hypersetup{
    bookmarksnumbered,
    bookmarksopen,
    pdftitle={\titleContent},
    pdfauthor={Amitabhha},
    pdfsubject={\runtitle},
    pdfcreator={XeLaTex(UbuntuMate14.04)}
}

%%%%%%%%%% reference %%%%%%%%%%
% 参考文献

% \bibliographystyle{buaathesis} % 参考文献格式
\RequirePackage[sort&compress]{natbib}
\bibpunct{[}{]}{,}{n}{}{} % provided by natbib, note formate in main text.正文中的标记格式
% \setlength{\bibsep}{0pt}
\RequirePackage{hypernat} %点击编号可跳转
%% 把原来cite变量对应的宏保存到oldamtbcite再引用，防止递归展开死循环。
% \let\oldamtbcite\cite
% \renewcommand{\cite}[1]{
%     \textsuperscript{\oldamtbcite{#1}}
% }

%%%%%%%%%% color %%%%%%%%%%\color{blue}
% 颜色设置

% 只用于电子版
\RequirePackage{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}